<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
</head>
<body>
    <input type="text"><button>查询</button>
    <div></div>
    <script>
        $('button').click(function(params){
            //获取输入框的值
            console.log($('input').val());
            //发送给后端
            $.ajax({
                type:'post',
                url:'http://192.168.0.30:8000/users/setname',
                data:{
                    username:$('input').val()
                },
                //请求数据格式
                // contentType:'application/x-www-form-urlencoded',
                // contentType:'application/json',
                // //上传文件
                // contentType:'application/form—data',
                success:(res)=>{
                console.log(res);
                $('div').append(`<p>${res.name}</p>`)
                },
                error:err=>{A
                    console.log(err);
                    
                },
                complete:ee=>{
                    //常用于关闭请求等待
                    console.log('无论成功与失败都执行');
                    
                }
            })

        })

    </script>
</body>
</html>